package main

import (
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
	"strconv"
	"time"
)

type BtcContext struct {
	Part       map[int]*PartLine
	NextTime   time.Time
	NextLabel  *widget.Label
	State      int
	StateLabel *widget.Label
	L          *widget.Entry
	LS         *container.Scroll
	Lt         int
	OutExcel   *widget.Entry
	OutChart   *widget.Entry
	ApiKey     *widget.Entry
	Max        *widget.Entry

	PairData []SavePair
}

func NewBtcContext() *BtcContext {
	return &BtcContext{}
}

func (b *BtcContext) GetRange(t string) []*RankPair {
	data := bc.PairData

	var rankPair []*RankPair
	for _, v := range data {
		l, _ := strconv.ParseFloat(v.Left, 64)
		r, _ := strconv.ParseFloat(v.Right, 64)
		rankPair = append(rankPair, NewRankPair(v.Index, l, r, 0, t))
	}

	return rankPair
}

func (b *BtcContext) Clear() {
	for _, line := range b.Part {
		line.Clear()
	}
}

func (b *BtcContext) Log(d string) {
	if b.Lt > 10 {
		b.Lt = 0
		b.L.SetText("")
	}
	if b.L != nil {
		b.L.Append(d + "\n")
	}
	b.Lt++
}
